package com.example.weather.utils;

import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.provider.ContactsContract;
import android.util.DisplayMetrics;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by hanjun on 2016/7/28.
 */
public class AppUtils {
    public static int[] getScreenHeightAndWidth(Context context){
        DisplayMetrics dm = new DisplayMetrics();
        ((Activity)context).getWindowManager().getDefaultDisplay().getMetrics(dm);
        return new int[]{dm.widthPixels,dm.heightPixels};
    }

    public static ArrayList<Map<String,Object>> getPhoneMessage(Context context){
        ArrayList<Map<String,Object>> arrayList = new ArrayList<>();
        Map<String,Object> map = new HashMap<>();
        Cursor cursor=context.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
        String phoneNumber;
        String phoneName;
        while (cursor.moveToNext()) {
            phoneNumber=cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
            phoneName=cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
            map.put("phoneNumber",phoneNumber);
            map.put("phoneName",phoneName);
            arrayList.add(map);
            map = new HashMap<>();
        }
        return arrayList;
    }
}
